<%@ page import="com.example.rk.entity.Admin" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>XXXX后端管理系统</title>
    <jsp:include page="../common_css.jsp"/>

    <style>
        .form-control{
            width: 30%;
        }
    </style>
</head>
<body>
<div class="container-scroller">
    <!-- partial:partials/_navbar.html -->
    <jsp:include page="../top.jsp"/>

    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
        <!-- partial:partials/_sidebar.html -->
        <jsp:include page="./left.jsp"/>
        <!-- partial -->
        <div class="main-panel">
            <div class="row">
                <div class="col-md-12 stretch-card">
                    <div class="card">
                        <div class="card-body">

                            <div class="table-responsive" align="center">
                                <form id="frm" class="form-signin">
                                    <h1 class="h3 mb-3 font-weight-normal">添加数据</h1>
                                    <label for="inputtitle" class="sr-only">题目</label>
                                    <input type="text" id="inputtitle" name="title" class="form-control" placeholder="题目" required autofocus>
                                    <label for="inputetype" class="sr-only">目标群体</label>
                                    <input type="text" id="inputetype"  name="type" class="form-control" placeholder="目标群体" required>
                                    <button class="btn btn-lg btn-primary btn-block" type="button" onclick="doAdd()" style="width: 30%">添加</button>
                                </form>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <jsp:include page="../footer.jsp"/>
    </div>
    <!-- main-panel ends -->
</div>
<!-- page-body-wrapper ends -->
</div>
<!-- container-scroller -->
<jsp:include page="../common_js.jsp"/>
</body>

</html>

<script>
    function doAdd() {
        //推荐前端js验证字段

        var inputtitle=$("#inputtitle").val();
        var inputtype=$("#inputtype").val();
        if (inputtitle==''|| inputtype==''){
            alert("不能为空");
        }else{
            $.ajax(
                {
                    type:"post",
                    url:"/choice/doAdd",
                    data:$("#frm").serialize(),
                    async:false,  //使用ajax同步提交数据
                    success:function (response) {
                        if (response=="exist"){
                            alert("添加失败，已经存在");
                        }else  if (response=="ok"){
                            alert("添加成功");
                            setTimeout(window.location.href="/choice/list",1000);
                        }else{
                            alert("添加失败");
                        }
                    }
                }
            );
        }
    }
</script>

